# 删除while循环

do_all_funcs = lambda fns, *args: [
    list(map(fn, *args)) for fn in fns
]

hello = lambda first, last: print("Hello", first, last)

bye = lambda first, last: print("Bye", first, last)

_ = do_all_funcs([hello, bye], ['David', 'Jane'], ['Mertz', 'Doe'])

def identity_print(x):
    print(x)
    return x

echo_FP = lambda: identity_print(input("FP --")) == 'quit' or echo_FP()
echo_FP()


#Currying(柯里化)的重要意义在于可以把函数完全变成【接受一个参数; 返回一个值】的固定形式

#惰性求值
from collections.abc import Sequence
class ExpandingSequence(Sequence):
    def __init__(self, it):
        self.it = it
        self._cache = []

    def __getitem__(self, index):
        while len(self._cache) <= index:
            self._cache.append(next(self.it))
        return self._cache[index]

    def __len__(self):
        return len(self._cache)








